﻿using System;
using System.Collections.Generic;
using System.IO;
using Syncfusion.Windows.PdfViewer;

namespace PdfSdk.PdfViewer
{
    public class StreamManager
    {
        private static readonly Type _type = Type.GetType($"Syncfusion.Windows.PdfViewer.StreamManager, {typeof(PdfDocumentView).Assembly.FullName}");

        public static readonly object LockerEx = new();

        public static Dictionary<int, Stream> _files
            => ObjectWrapper.GetFieldValue(_type) as Dictionary<int, Stream>;

        public static int Register(Stream stream)
        {
            return Convert.ToInt32(ObjectWrapper.InvokeMethod(_type, "Register", stream));
        }

        public static void Unregister(int id)
        {
            ObjectWrapper.InvokeMethod(_type, "Unregister", id);
        }

        public static Stream Get(int id)
        {
            return ObjectWrapper.InvokeMethod(_type, "Get", id) as Stream;
        }
    }
}
